package com.liu.qqserver.server;
import java.util.HashMap;
import java.util.Iterator;

/**
 * 服务端线程集合
 */
public class ManageServerThreads {
    public static HashMap<String,ServerConnectClientThread> hm = new HashMap<>();

    public static HashMap<String, ServerConnectClientThread> getHm() {
        return hm;
    }

    //添加线程对象到线程集合
    public static void addClientThreads(String userId,ServerConnectClientThread scct){
        hm.put(userId,scct);
    }
    //根据userId返回线程
    public static ServerConnectClientThread getClientThread(String userId) {
        return hm.get(userId);
    }
    //编写一个方法从集合中【移除一个线程
    public static void removeClientThread(String userId) {
        hm.remove(userId);
    }
    //编写一个方法返回在线列表
    public static String getOnlineUsers() {
        Iterator<String> iterator = hm.keySet().iterator();
        String onlineUsersList = "";
        while (iterator.hasNext()) {
            onlineUsersList += iterator.next().toString() + " ";
        }
        return onlineUsersList;
    }
}
